package wiki.generic.iotests;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import wiki.generic.io.Element;
import wiki.generic.io.ElementsMapReader;
import wiki.generic.utilities.Substring;

/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 *
 */
public class ConcreteElementsMapReader implements ElementsMapReader {

	@Override
	public HashMap<Integer, Element> getElementsMap(String path) {
		
		HashMap<Integer, Element> map=new HashMap<Integer, Element>();
		File f=new File(path);
		try {
			BufferedReader r=new BufferedReader(new FileReader(f));
			String s=r.readLine();
			while(s!=null){
				Substring sub=new Substring(s, "$$||$$");
				int ID=Integer.parseInt(sub.nextSubString());
				String elemento=sub.nextSubString();
				String owner=sub.nextSubString();
				map.put(ID,new Element(elemento, owner));
				s=r.readLine();
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return map;
	}
}
